<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/25
  Time: 10:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path=request.getScheme()+"://"
            +request.getServerName()+":"
            +request.getServerPort()+
            request.getContextPath()+"/";
%>
<html>
<head>
    <base href="<%=path%>">
    <title>cookieRegister</title>
</head>
<body>
<%
//    定义变量
    String userName = "";
    String pwd = "";
//    获取cookies值
    Cookie[] cookies=request.getCookies();
//    判空
    if(cookies!=null && cookies.length>0){
        for (Cookie co : cookies) {
//            给用户名赋值
            if(co.getName().equals("userName")){
                userName=co.getValue();
            }
//            给密码赋值
            if(co.getName().equals("pwd")){
                pwd=co.getValue();
            }
//            响应cookie
            response.addCookie(co);
        }
    }



%>
<form action="<%=path%>cookieSave.jsp" method="post">

    <table border="1">
        <tr>
            <td>用户名：</td>
            <td><input type="text" name="userName" value="<%=userName%>"></td>
        </tr>
        <tr>
            <td>密码：</td>
            <td><input type="password" name="pwd" value="<%=pwd%>"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="checkbox" name="flag">记住用户名</td>
        </tr>
        <tr>
            <td colspan="2">
                <button type="submit">登录</button>
            </td>
        </tr>
    </table>
</form>

</body>
</html>
